package cn.edu.zafu.bigdata.zyf;

public class DivideExceptionHandling {

    // 方法divide，当分母为0时抛出ArithmeticException
    public static int divide(int a, int b) {
        if (b == 0) {
            throw new ArithmeticException("Cannot divide by zero");
        }
        return a / b;
    }

    public static void main(String[] args) {
        int a = 10;
        int b = 0;

        try {
            // 尝试调用divide方法
            int result = divide(a, b);
            System.out.println("The result is: " + result);
        } catch (ArithmeticException e) {
            // 捕获异常并输出提示信息
            System.out.println("Error: " + e.getMessage());
        }
    }
}